package com.ruoyi.quartz.task;

import cn.hutool.core.text.CharSequenceUtil;
import com.ruoyi.constant.TaxiConstant;
import com.ruoyi.management.basics.service.ITCarService;
import com.ruoyi.management.basics.vo.GetOperateNumVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 运营车辆数存入redis
 * 
 * @author lss
 */
@Component("saveOperateNumTask")
public class SaveOperateNumTask
{
    @Autowired
    private ITCarService carService;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 运营车辆数存入redis
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveOperateNum(){
        List<GetOperateNumVo> voList = carService.getOperateNum();
        for (GetOperateNumVo vo : voList) {
            Integer companyId = vo.getCompanyId();
            Integer operateNum = vo.getOperateNum();
            String operateNumKey = CharSequenceUtil.format(TaxiConstant.OPERATE_NUM_CAR_KEY,companyId);
            redisTemplate.opsForValue().set(operateNumKey, operateNum);
        }
    }

}
